//
//  AnniversaryViewController.swift
//  BirthdayManager
//
//  Created by Saltsweet on 2020/12/18.
//  Copyright © 2020年 Charles. All rights reserved.
//

import UIKit

class AnniversaryViewController: UIViewController,UINavigationControllerDelegate, UIImagePickerControllerDelegate {

    @IBOutlet weak var headimg: UIImageView!
    @IBOutlet weak var dayname: UITextField!
    @IBOutlet weak var date: UIDatePicker!
    
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        let selectedImage = info[UIImagePickerController.InfoKey.originalImage]as? UIImage
        self.headimg.image = selectedImage
        dismiss(animated: true, completion: nil)//释放当前摄像头或相册界面
    }

    @IBAction func camera(_ sender: Any) {
        let imagePicker = UIImagePickerController()
        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.photoLibrary) {
            imagePicker.delegate = self
            imagePicker.sourceType = .photoLibrary
            present(imagePicker,animated: true,completion: nil)
        }
        
    }
    @IBAction func tab(_ sender: Any) {
        let imagePicker = UIImagePickerController()
        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.photoLibrary) {
            imagePicker.delegate = self
            imagePicker.sourceType = .photoLibrary
            present(imagePicker,animated: true,completion: nil)
        }
    }
    
    var dayForEdit: dayinfo?
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        // 绑定cell中的图片和文本到详情页对应位置
        if let day=dayForEdit {
            headimg.image = day.headimg
            dayname.text = day.dayname
            date.date = day.date!
        }
        
    }
    
    override func viewDidAppear(_ animated: Bool) {
        print("reload")
    }
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
        if segue.identifier == "save"{
            dayForEdit = dayinfo(headimg: headimg.image!, dayname: dayname.text!, date: date.date)}
        
    }
    

}
